const cloud = require('wx-server-sdk')

cloud.init({
  env: 'gezi-ofhmx'
})
exports.main = async (event, context) => {
  try {
    var data={};
    if(event.thing8){
      data ={
        thing8: {
          value: event.thing8
        },
        time2: {
          value: event.time2
        }
      }
    }else{
      data ={
        thing1: {
          value: event.thing1
        },
        thing2: {
          value: event.thing2
        },
        time3: {
          value: event.time3
        }
      }
    }
    if(event.type==3){
      data ={
        name3: {
          value: event.name3
        },
        phrase2: {
          value: event.phrase2
        },
        thing1: {
          value: event.thing1
        },
        date4: {
          value: event.date4
        }
      }
    }
    const result = await cloud.openapi.subscribeMessage.send({
        touser: event.openid,
        page: event.page,
        lang: 'zh_CN',
        data: data,
        templateId: event.templateId,
        miniprogramState: event.miniprogramState
      })
    return result
  } catch (err) {
    return err
  }
}